<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>中线为轴3D翻转</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            width: 100vw;
            background-color: #f0f0f0;
            margin: 0;
        }

        .flip-container {
            width: 100vw;
            height: 200px;

            position: relative;
            transform-style: preserve-3d;
            transition: transform 1s;
            transform-origin: center center; /* 关键修改：设置中线为旋转轴 */
        }

        .flip-container.flipped {
            transform: rotateY(180deg);
        }

        .front, .back {
            position: absolute;
            width: 100%;
            height: 100%;
            backface-visibility: hidden;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 24px;
            border-radius: 10px;
        }

        .front {
            background-color: #3498db;
            color: white;
        }

        .back {
            background-color: #e74c3c;
            color: white;
            transform: rotateY(180deg);
        }

        button {
            margin-top: 20px;
            padding: 10px 20px;
            font-size: 16px;
            cursor: pointer;
        }
    </style>
</head>
<body>
<div>
    <div class="flip-container" id="flipper">
        <div class="front">正面内容</div>
        <div class="back">背面内容</div>
    </div>
    <button onclick="flipCard()">点击翻转</button>
</div>

<script>
    function flipCard() {
        const flipper = document.getElementById('flipper');
        flipper.classList.toggle('flipped');
    }

    // 自动翻转（5秒后）
    setTimeout(() => {
        const flipper = document.getElementById('flipper');
        flipper.classList.add('flipped');
    }, 5000);
</script>
</body>
</html>
